$(
	function(){

		
		$("body").bind(fffCommerce.events.SHOW_DETAILS,function(event,productId){
			new fffCommerce.Details().displayDetails(productId);
		});
		
		
		//alert(typeof myCart);	
	}
);

fffCommerce = fffCommerce || {};
fffCommerce.Details = function(){};

fffCommerce.Details.prototype = {
	
	sortPhotos:function(photos){
		return photos.sort(
			function(photo1, photo2){
				return photo1.priority < photo2.priority ? 
					-1 :
					photo1.priority > photo2.priority ?  1 : 0
			});
	},
	
	displayDetails: function(productId){
		
		var _self = this;
		fffCommerce.api.Products.getItem(productId, function(data){
			_self.fillDetailsPlaceholder(data);
		})
		
	},
	
	fillDetailsPlaceholder: function(product){
				
		$.get(
			"./details.html",
			function(data){
				$('#details').html(data);
				$("#image").attr("src", product.photoThumbnailUrl);
				$("#shortName").text(product.shortName);
				$("#longName").text(product.longName);
				$("#description").text(product.description);
				$("#price").text(product.price);
				
				$("#btnAddToCart").click(function(){new Cart().addProd(product)});
				$("#prevImage").click(function(){
					$("#image").attr("src", product.photoThumbnailUrl);
				});
				$("#nextImage").click(function(){
					$("#image").attr("src", product.photoThumbnailUrl);
				});
			});
	}
};
fffCommerce.Details.prototype.contructor = fffCommerce.Details;